#include "menu3.h"

// 1. Base class constructor
Rectifier::Rectifier(double voltage, double resistance) : voltage(voltage), resistance(resistance) {}

// 2. Half-Wave Rectifier constructor
HalfWaveRectifier::HalfWaveRectifier(double voltage, double resistance) : Rectifier(voltage, resistance) {}

// 3. Full-Wave Rectifier constructor
FullWaveRectifier::FullWaveRectifier(double voltage, double resistance) : Rectifier(voltage, resistance) {}

// 4. Half-wave rectification
void HalfWaveRectifier::rectification() const {
    double averageVoltage = (voltage * sqrt(2)) / PI;
    double averageCurrent = averageVoltage / resistance;
    double maxDiodeVoltage = voltage * sqrt(2);
    double averageDiodeCurrent = averageCurrent;

    std::cout << "\n---------------------------- Half-Wave Rectification Results ----------------------------\n";
    std::cout << "|\t\t\t\t\t\t\t\t\t\t\t|\n";
    std::cout << "|\t1. Load voltage (in V): " << averageVoltage << "\t\t\t\t\t\t\t|\n";
    std::cout << "|\t2. Average current flowing through the load resistance (in A): " << averageCurrent << "\t\t|\n";
    std::cout << "|\t3. Maximum reverse voltage of diode (in V): " << maxDiodeVoltage << "\t\t\t\t|\n";
    std::cout << "|\t4. Average current flowing through diode (in A): " << averageDiodeCurrent << "\t\t\t|\n";
    std::cout << "|\t\t\t\t\t\t\t\t\t\t\t|\n";
    std::cout << "-----------------------------------------------------------------------------------------\n";
    
}

// 5. Full-wave rectification
void FullWaveRectifier::rectification() const {
    double averageVoltage = (voltage * sqrt(2) * 2) / PI;
    double averageCurrent = averageVoltage / resistance;
    double maxDiodeVoltage = voltage * sqrt(2);
    double averageDiodeCurrent = averageCurrent * 0.5;

    std::cout << "\n---------------------------- Full-Wave Rectification Results ----------------------------\n";
    std::cout << "|\t\t\t\t\t\t\t\t\t\t\t|\n";
    std::cout << "|\t1. Load voltage (in V): " << averageVoltage << "\t\t\t\t\t\t\t|\n";
    std::cout << "|\t2. Average current flowing through the load resistance (in A): " << averageCurrent << "\t\t|\n";
    std::cout << "|\t3. Maximum reverse voltage of diode (in V): " << maxDiodeVoltage << "\t\t\t\t|\n";
    std::cout << "|\t4. Average current flowing through diode (in A): " << averageDiodeCurrent << "\t\t\t|\n";
    std::cout << "|\t\t\t\t\t\t\t\t\t\t\t|\n";
    std::cout << "-----------------------------------------------------------------------------------------\n";
    
}